package cn.ubeta.b2c;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.cart.CheckoutActivity;
import cn.ubeta.b2c.common.AnalyseActivity;
import cn.ubeta.b2c.utils.AppConfig;
import cn.ubeta.b2c.utils.Constants;
import cn.ubeta.b2c.utils.ToastHelper;

/**
 * Created by denny on 2016/10/20.
 */

public class PreConfigActivity extends AnalyseActivity {

    // 银行卡
    private TextView mTvPayType;
    // 发票
    private EditText mEtBillTitle;
    private CheckBox mCbEcleBill;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        onCreate(savedInstanceState, R.layout.activity_pre_config);

        // 支付方式
        mTvPayType = ((TextView) findViewById(R.id.tv_paytype));
        findViewById(R.id.ll_paytype).setOnClickListener(v -> CheckoutActivity.gotoSelectJdBandCard(this));
        refreshPreConfigPayCard();

        // 发票
        mEtBillTitle = (EditText) findViewById(R.id.et_bill_title);
        mCbEcleBill = (CheckBox) findViewById(R.id.cb_elec_bill);

        mEtBillTitle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String text = editable.toString();
            }
        });

        // 检查是否有没填写的
        checkPreConfigInfo();
    }

    /**
     * 检查是否有没填的下单配置
     */
    private void checkPreConfigInfo() {
        String msg = null;
        if (AppConfig.getPreConfigAddressInfo().getAddressId() == 0) {
            msg = "请选择收货地址";
        } else if (TextUtils.isEmpty(AppConfig.getPreConfigJdPayCardTitle())) {
            msg = "请选择京东支付银行卡";
        }
        if (!TextUtils.isEmpty(msg)) {
            ToastHelper.show(msg);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.REQ_CODE_ADDRESS && resultCode == RESULT_OK) {
            // 选择地址
        }
    }

    /**
     * 刷新京东支付银行卡号
     */
    private void refreshPreConfigPayCard() {
        String cardNo = AppConfig.getPreConfigJdPayCardTitle();
        mTvPayType.setText(TextUtils.isEmpty(cardNo) ? "请选择京东快捷支付银行卡" : cardNo);
    }


}
